const { AsyncSeriesHook } = require('tapable');
let hook = new AsyncSeriesHook(['name', 'age']);
console.time('cost');
/* 

hook.tapAsync("1", (name, age, callback) => {
    setTimeout(() => {
        console.log('1', name, age);
        callback();
    }, 1000);
});

hook.tapAsync("2", (name, age, callback) => {
    setTimeout(() => {
        console.log('2', name, age);
        callback();
    }, 2000);
});
hook.tapAsync("3", (name, age, callback) => {
    setTimeout(() => {
        console.log('3', name, age);
        callback();
    }, 3000);
});
hook.callAsync('zhufeng', 12, (err) => {
    console.log('ok');
    console.timeEnd('cost');
}); */


hook.tapPromise('1', function (name, age) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('1', name, age);
            resolve();
        }, 1000);
    });
});
hook.tapPromise('2', function (name, age) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('2', name, age);
            resolve();
        }, 2000);
    });
});
hook.tapPromise('3', function (name, age) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('3', name, age);
            resolve();
        }, 3000);
    });
});
hook.promise('zhufeng',12).then(()=>{
    console.log('success');
    console.timeEnd('cost');
},()=>{
    console.log('fail');
    console.timeEnd('cost');
});